﻿<?php
if(!defined('IN_PHPSCUP'))exit('hacking'); 

class CompanynewApp extends BaseApp
{

    var $type = 'companynew';
	
	
    function index()
    {
        if(!isset($_POST['word']))
		{
		$_POST['word'] = '';
		}
        if(!isset($_GET['v']))
		{
		$_GET['v'] = '';
		}		
		
	    $word = $_POST['word'];
		$word_array = explode(' ',$word);
		
		foreach($word_array as $key => $value)
		{
			if(!$value)
			{
             unset($word_array[$key]);
		    }  
		}
		 
        $order = '';
		$v = $_GET['v'];
		if($v == 'timeasc')
		{
        $order = 'add_time asc';
		}
		else if($v == 'timedesc')
		{
        $order = 'add_time desc';		
		}
		else if($v == 'showyes')
		{
        $order = 'is_show desc';		
		}
		else if($v == 'showno')
		{
        $order = 'is_show asc';		
		}
		else if($v == 'topyes')
		{
        $order = 'is_top desc';		
		}
		else if($v == 'topno')
		{
        $order = 'is_top asc';		
		}
		else if($v == 'recyes')
		{
        $order = 'is_recommend desc';		
		}
		else if($v == 'recno')
		{
        $order = 'is_recommend asc';		
		}
		else if($v == 'indexyes')
		{
        $order = 'is_index desc';		
		}
		else if($v == 'indexno')
		{
        $order = 'is_index asc';		
		}
				
	
	
	
		$TB_new = &$this->_model('new');
				
		$data = $TB_new->show($order,$v,$word_array,$GLOBALS['SCup']->SCup_user_msg['user_id']);	
			
        $this->assign('lw_data', $data['data']);		
		$this->assign('lw_page', $data['page']);	
		
		
/*	 	$categorydata = & $GLOBALS['SCup']->_get_category_data($this->type);
		if(!is_array($categorydata))
		{
		 $categorydata = (array)$categorydata;
		}		
		$categorylist = array();
		foreach($categorydata as $value)
		{
		    $categorylist[$value['cat_id']] = $value['cat_name'];
		}	
		
        $this->assign('categorylist', $categorylist);	*/						
	    
		$this->assign('word', $word);
		$this->assign('v', $v);
		
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	       
		 $this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	        $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',SITE_URL.'/'.$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
		
        $this->display('company/companynewlist.view.html');
    }

    function add()
    {
		
	
		$TB_new = &$this->_model('new'); 
		
		$id_array = $TB_new->select_id($GLOBALS['SCup']->SCup_user_msg['user_id']);		
		foreach($id_array as $value)
		{
		 del_file(ROOT_PATH . '/' . UPFILE_PATH . '/' . $this->type . '/' .$GLOBALS['SCup']->SCup_user_msg['user_id'].'/'. $value['id'] . '/');	
		}		
		$TB_new->delet_id($GLOBALS['SCup']->SCup_user_msg['user_id']);	
		
				
		$data_id = $TB_new->insert_id($GLOBALS['SCup']->SCup_user_msg['user_id']);
		

		$data = array();
		$data['id'] = $data_id;
        $this->assign('data', $data);	
        $this->assign('id', $data_id);				
        $this->assign('keyworddata', del_empty_var(explode('+', AWAY_USE_KEYWORD)));	
        $this->assign('zhandian', del_empty_var(explode('+', AWAY_USE_ZHANDIAN)));		

	 	 $TB_company= &$this->_model('company');		 		 		
		 $companydata = $TB_company->oneshow($GLOBALS['SCup']->SCup_user_msg['user_id']);
         $company_id = $companydata['id'];


        include(ROOT_PATH."/lib/companycategory.lib.php");	
		$category= new Companycategory();	
	 	$categorydata = $category->_get_category_data($this->type,$company_id);
		   
        $this->assign('categorydata', $categorydata);		
		
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	       
		 $this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	        $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',SITE_URL.'/'.$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');		
		
        $this->display('company/companynewadd.view.html');
    }
	

    function kindeditor()
    {
    $w = intval($_GET['w']);
    include(ROOT_PATH."/data/ewebeditor/ewebeditor.lib.php");	
	$kindeditor = new Ewebeditor(array('imageUploadCgi'=>SITE_URL.'/index.php?app='.$this->type.'&act=kindeditorupfile&w='.$w));
	$kindeditor->show();
	
    }
	
    function kindeditorupfile()
    {
    $w = intval($_GET['w']);
    include(ROOT_PATH."/data/ewebeditor/ewebeditor.lib.php");	
	$kindeditor = new Ewebeditor(array('imageUploadCgi'=>SITE_URL.'/index.php?app='.$this->type.'&act=kindeditorupfile&w='.$w));
	$kindeditor->upfile($this->type.'/'.$GLOBALS['SCup']->SCup_user_msg['user_id'].'/'.$w);	
	
    }
		
	

    function cagryadd()
    {
	

        include(ROOT_PATH."/lib/companycategory.lib.php");	
		$category= new Companycategory();	
		 		 		
		$catgydata = $category->show($this->type,$GLOBALS['SCup']->SCup_user_msg['user_id']);
		
		$catgystr = $category->html_format_category($catgydata,0);	

        $this->assign('catgystr', $catgystr);	
		
        $this->assign('category_value', $this->type);
			    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display('company/companycagryadd.view.html');
    }
	
    function editcatgy()
    {
	
	
		$id= intval($_GET['id']);
		
        include(ROOT_PATH."/lib/companycategory.lib.php");	
		$category= new Companycategory();	
		 		 		
		$catgydata = $category->show($this->type,$GLOBALS['SCup']->SCup_user_msg['user_id']);
		
		$data = $category->oneshow($id,$GLOBALS['SCup']->SCup_user_msg['user_id']);
		
		$catgystr = $category->html_format_category($catgydata,$data['parent_id'],0,0,$id);	
        $this->assign('data', $data);

        $this->assign('catgystr', $catgystr);
		
        $this->assign('category_value', $this->type);
			    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	       
		 $this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	        $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',SITE_URL.'/'.$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
			
		
        $this->display('company/companycagryedit.view.html');
    }
	
    function cagrylist()
    {
	
        include(ROOT_PATH."/lib/companycategory.lib.php");	
		$category= new Companycategory();	
		 		 		
		$catgydata = $category->show($this->type,$GLOBALS['SCup']->SCup_user_msg['user_id']);
		$catgydata = $category->get_list_category($catgydata);

		
        $this->assign('catgydata', $catgydata);				

        $this->assign('category_value', $this->type);
	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
			
        $this->assign('login_icon', $GLOBALS['SCup']->SCup_user_checking);	       
		 $this->assign('langtype', trim($GLOBALS['Lang']->_lang_tp));
	        $this->assign('site_url',SITE_URL);	
		$this->assign('bg_pic_url',SITE_URL.'/'.$GLOBALS['SCup']->SCup_name.'/view/'.VIEW_TYPE .'/style/'.CSS_TYPE.'/');	
		
        $this->display('company/companycagrylist.view.html');
    }

    function cyaddpost()
    {

	     $data = $_POST['data'];

	 	 $TB_company= &$this->_model('company');		 		 		
		 $companydata = $TB_company->oneshow($GLOBALS['SCup']->SCup_user_msg['user_id']);
         $data['company_id'] = $companydata['id'];
         $data['userid'] = $GLOBALS['SCup']->SCup_user_msg['user_id'];
         include(ROOT_PATH."/lib/companycategory.lib.php");	
		 $category= new Companycategory();	
		 		 		
		 $category->post($data);
		 
		 $category->write_cache($this->type,$data['userid'],$data['company_id']);	
		 	 		 
		 $notice = &get_message(array('msg'=>"添加成功！",'url'=>'?app=companynew&act=cagrylist','title'=>'Notice'));
		 $notice ->display();	

    }


    function cyeditpost()
    {

	     $id = $_POST['id'];
	     $data = $_POST['data'];

		 		 
	 	 $TB_company= &$this->_model('company');		 		 		
		 $companydata = $TB_company->oneshow($GLOBALS['SCup']->SCup_user_msg['user_id']);         
         $data['company_id'] = $companydata['id'];
         $data['userid'] = $GLOBALS['SCup']->SCup_user_msg['user_id'];
	
         include(ROOT_PATH."/lib/companycategory.lib.php");	
		 $category= new Companycategory();		 		 		
		 $category->editaction($id,$data,$GLOBALS['SCup']->SCup_user_msg['user_id']);

		 $category->write_cache($this->type,$data['userid'],$data['company_id']);
		 	 		 
		 $notice = &get_message(array('msg'=>"修改成功！",'url'=>'?app=companynew&act=cagrylist','title'=>'Notice'));
		 $notice ->display();	

    }
	
    function delcatgy()
    {
		$id= intval($_GET['id']);		
	 	 $TB_company= &$this->_model('company');		 		 		
		 $companydata = $TB_company->oneshow($GLOBALS['SCup']->SCup_user_msg['user_id']);
         $data['company_id'] = $companydata['id'];		          
         include(ROOT_PATH."/lib/companycategory.lib.php");	
		 $category= new Companycategory();	
		 	 		 		
		$category->del($id,$GLOBALS['SCup']->SCup_user_msg['user_id']);
		
		$category->write_cache($this->type,$GLOBALS['SCup']->SCup_user_msg['user_id'],$data['company_id']);
				      
		 $notice = &get_message(array('msg'=>"删除成功！",'url'=>'?app=companynew&act=cagrylist','title'=>'Notice'));
		 $notice ->display();	 
    }	
	
    function addpost()
    {

	     $data = $_POST['data'];
		 $id = $_POST['id'];
/*         if(!isset($data['cat_id'])||empty($data['cat_id']))
		{
		 $notice = &get_message(array('msg'=>"所属栏目不能为空!",'url'=>'','title'=>'Notice'));
		 $notice ->display();		 
		 }*/
		 		 
		 $data['user_id'] = $GLOBALS['SCup']->SCup_user_msg['user_id'];
		 $data['user_name'] = $GLOBALS['SCup']->SCup_user_msg['data']['user_name'];	 
		/* $data['config'] = serialize(array('titlecolor'=>$data['titlecolor'],'fonttype'=>$data['fonttype']));*/
         $data['config'] = serialize(array('titlecolor'=>'','fonttype'=>''));
		 if(empty($data['yz']))
		 {
		    $data['yz']='0';
		 }  
		 if(empty($data['top']))
		 {
		    $data['top']='0';
		 }  
		 if(empty($data['levels']))
		 {
		    $data['levels']='0';
		 }  
		 if(empty($data['special']))
		 {
		    $data['special']='0';
		 }  		 
	 	 $TB_company= &$this->_model('company');		 		 		
		 $companydata = $TB_company->oneshow($GLOBALS['SCup']->SCup_user_msg['user_id']);
         $data['company_id']=$companydata['id'];			          

		 $TB_new = &$this->_model('new'); 
		 		 		
		 $TB_new->post($id,$data,$GLOBALS['SCup']->SCup_user_msg['user_id']);

		 $notice = &get_message(array('msg'=>"添加成功!",'url'=>'','title'=>'Notice'));
		 $notice ->display();

    }

    function upfile()
    {
	 if(!isset($_POST["action"]))
	 {
	 $_POST["action"]='';
	 }
	 if(!isset($_GET['id']))
	 {
	 $_GET['id']='';
	 }
	 if(!isset($_GET["edit"]))
	 {
	 $_GET["edit"]='';
	 }	 
	 if(!isset($_GET["picurl"]))
	 {
	 $_GET["picurl"]='';
	 }	
	 if(!isset($_GET['jsfun']))
	 {
	 $_GET['jsfun']='';
	 }		 
	 if(!isset($_GET['putid']))
	 {
	 $_GET['putid']='';
	 }		 
	 if(!isset($_GET['uppic']))
	 {
	 $_GET['uppic']='';
	 }		 	
		$action = $_POST["action"];		
		$id = intval($_GET['id']);		
		$jsfun = $_GET['jsfun'];
		$uppic = $_GET['putid'];
		if(!empty($_GET['uppic']))
		{
		$uppic = $_GET['uppic'];		
		}	
		$edit = $_GET["edit"];
		$picurl = $_GET["picurl"];

        $this->assign('jsfun', $jsfun);		


        $this->assign('uppic', $uppic);		
	
				

        $this->assign('edit', $edit);		


        $this->assign('picurl', $picurl);


						
		if($action == 'post')
		{
			 if(!isset($_POST['jsfun']))
	 {
	 $_POST['jsfun']='';
	 }	
	 if(!isset($_POST['uppic']))
	 {
	 $_POST['uppic']='';
	 }		 
	 if(!isset($_POST["edit"]))
	 {
	 $_POST["edit"]='';
	 }		 
	 if(!isset($_POST["picurl"]))
	 {
	 $_POST["picurl"]='';
	 }	
	 if(!isset($_POST['id']))
	 {
	 $_POST['id']='';
	 }		 
		       $jsfun = $_POST['jsfun'];
		       $uppic = $_POST['uppic'];		
		       $edit = $_POST["edit"];
		       $picurl = $_POST["picurl"];
		 	   $id || $id = intval($_POST['id']);		
		       $filedname = trim(str_replace(array("UP_"),array(""),$uppic)); 
       
		       include(ROOT_PATH.'/lib/upfile.lib.php');	  
	           $upfile = new Upfile($this->type.'/'.$GLOBALS['SCup']->SCup_user_msg['user_id'].'/'.$id); 	  
	           $updata = $upfile->_batch_upfile($this->type);		 
		 		 
		       $newfile = $updata[1]['path'];
	       
			   if($edit=='editp' && $picurl)
			   {

			          $TB_new = &$this->_model('content');			    		 		 		
		              $TB_new->editpicurl($id,array("$filedname"=>$newfile),$this->table_id);
		              $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $picurl;
		              del_file($pic_dir);				   
			   }

			    if($edit=='edit' && $picurl)
		       {
		              $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $picurl;
		              del_file($pic_dir);			 
		       }
		
		      $pic_url = SITE_URL . '/' . UPFILE_PATH . '/' .$newfile;

	    echo "<img src='{$pic_url}' id='upsrc' width='100px' height='100px'><br/><A HREF='?app={$this->type}&act=upfile&edit=$edit&picurl=$newfile&id=$id&jsfun=$jsfun&uppic=$uppic'>修改图片</A>";

	    echo "<script>
				if(self==top){
					window.opener.$jsfun('$newfile','$uppic');
					window.self.close();
				}else{
					window.parent.$jsfun('$newfile','$uppic');
				}
		     </script>";
				
	    exit;		
		
		}

        $this->assign('id', $id);
	    $this->assign('app', $this->type);		    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display('upfile.view.php');
    }




    function pupfile()
    {	
	 if(!isset($_GET["action"]))
	 {
	 $_GET["action"]='';
	 }
	 if(!isset($_POST["action"]))
	 {
	 $_POST["action"]='';
	 }
	 if(!isset($_GET['id']))
	 {
	 $_GET['id']='';
	 }
	        if(!isset($_POST['id']))
	        {
	          $_POST['id']='';
	        }  	
		$action = $_GET["action"];			
		$action || $action = $_POST["action"];
		
		$id = intval($_GET['id']);
		$cid =$id;
				
		if($action == 'post')
		{
		
		 	   $id || $id = intval($_POST['id']);		
               $cid = $id;
		       include(ROOT_PATH.'/lib/upfile.lib.php');	  
	           $upfile = new Upfile($this->type.'/'.$id); 	  
	           $updata = $upfile->_batch_upfile($this->type);		 
		 		 
		       $newfile = $updata[1]['path'];
			   
               unset($data);
		       $data['uid'] = $GLOBALS['SCup']->SCup_user_msg['user_id'];		       
               $data['con_id'] = $id;
               $data['appname'] = $this->type;			   
			   $data['file_url'] = $updata[1]['path'];
			   $data['size'] = $updata[1]['size'];
			   $data['type'] = $updata[1]['type'];
			   				   $data['appname'] = $this->type.'';			   
			   $TB_new = &$this->_model('upfile');			    		 		 		
		       $TB_new->post($data);
					   	   
	    }
		else if($action == 'del')
		{
			   $id || $id = intval($_POST['id']);   
			   $TB_new = &$this->_model('upfile');
			   
			    $picdata = $TB_new->oneshow($id);
				$picurl = $picdata['file_url'];
                $cid = $picdata['con_id'];
			   			    		 		 		
		       $TB_new->del($id);
					  
		       $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $picurl;
		       del_file($pic_dir);			
		
		}			

	    $TB_new = &$this->_model('upfile');

        $this->assign('picdata', $TB_new ->selct($cid,$this->type));		
	
        $this->assign('id', $cid);
	    $this->assign('app', $this->type);					    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('pupfile.view.php');
    }





    function edit()
    {
		$id= intval($_GET['id']);
		
		$TB_new = &$this->_model('new');
				
		$data = $TB_new->oneshow($id,$GLOBALS['SCup']->SCup_user_msg['user_id']);	
		
		$data['content'] = str_replace("'", "&rsquo;", $data['content']);		
			
        $this->assign('keyworddata', del_empty_var(explode('+', AWAY_USE_KEYWORD)));	
        $this->assign('zhandian', del_empty_var(explode('+', AWAY_USE_ZHANDIAN)));
	 	 $TB_company= &$this->_model('company');		 		 		
		 $companydata = $TB_company->oneshow($GLOBALS['SCup']->SCup_user_msg['user_id']);
         $company_id = $companydata['id'];


        include(ROOT_PATH."/lib/companycategory.lib.php");	
		$category= new Companycategory();	
	 	$categorydata = $category->_get_category_data($this->type,$company_id);
		
        $this->assign('categorydata', $categorydata);

        $this->assign('data', $data);

        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display('company/companynewedit.view.html');     

    }

    function editpost()
    {
		$id= intval($_POST['id']);
		
		$data = $_POST['data'];
/*         if(!isset($data['cat_id'])||empty($data['cat_id']))
		{
		 $notice = &get_message(array('msg'=>"所属栏目不能为空!",'url'=>'','title'=>'Notice'));
		 $notice ->display();		 
		 }
		*/
		
		
		 $data['user_id'] = $GLOBALS['SCup']->SCup_user_msg['user_id'];
		 $data['user_name'] = $GLOBALS['SCup']->SCup_user_msg['data']['user_name'];	 
/*		 $data['config'] = serialize(array('titlecolor'=>$data['titlecolor'],'fonttype'=>$data['fonttype']));*/
         $data['config'] = serialize(array('titlecolor'=>'','fonttype'=>''));
		 if(empty($data['yz']))
		 {
		    $data['yz']='0';
		 }  
		 if(empty($data['top']))
		 {
		    $data['top']='0';
		 }  
		 if(empty($data['levels']))
		 {
		    $data['levels']='0';
		 }  
		 if(empty($data['special']))
		 {
		    $data['special']='0';
		 }  		 
	 	 $TB_company= &$this->_model('company');		 		 		
		 $companydata = $TB_company->oneshow($GLOBALS['SCup']->SCup_user_msg['user_id']);
         $data['company_id']=$companydata['id'];
		 			  
 		$TB_new = &$this->_model('new');  
				
		$TB_new->editaction($id,$data,$GLOBALS['SCup']->SCup_user_msg['user_id']);
		          

		 $notice = &get_message(array('msg'=>"修改成功!",'url'=>'','title'=>'Notice'));
		 $notice ->display();	      

    }
	
	

    function del()
    {
		$id= intval($_GET['id']);	
		del_file(ROOT_PATH . '/' . UPFILE_PATH . '/' . $this->type.'/'.$GLOBALS['SCup']->SCup_user_msg['user_id'].'/'.$id);			
		
		$TB_new = &$this->_model('new');
		
		$TB_new->del($id,$GLOBALS['SCup']->SCup_user_msg['user_id']);

		 $notice = &get_message(array('msg'=>"删除成功!",'url'=>'','title'=>'Notice'));
		 $notice ->display();	  
    }	
	
    function lcsort()
    {
		$id= intval($_GET['id']);
		$v= intval($_GET['v']);		
        unset($data);
		$data[sort_order] = $v;
		
	    $category = & $GLOBALS['SCup']->_get_category();		 		 		
		$category->editsort($id,$data);
		
		$category->write_cache($this->type);	
					      
		$this->cagrylist();   
    }	
		

		

}





?>